package com.ruoyi.framework.config;

import com.ruoyi.framework.interceptor.JwtInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName WebInterceptor
 * @Description 设置拦截器，token等验证
 * @Author tyc@yanyu
 * @Date 2018/12/29 0029 15:21
 **/
@Configuration
public class WebInterceptor implements WebMvcConfigurer {

   /* @Bean
    public HandlerInterceptor getTokenInterceptor(){
        return new JwtInterceptor();
    }*/

    //添加拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
       /* registry.addInterceptor(getTokenInterceptor())    //指定拦截器类
                .addPathPatterns("/app/**")
                .excludePathPatterns("/app/register/**");//指定该类不拦截的url*/
    }

    @Override
    public void addCorsMappings(CorsRegistry registry) {
        // 设置请求跨域
        registry.addMapping("/app/**")
                .allowedOrigins("*")
                .allowedHeaders("*")
                .allowCredentials(true)
                .allowedMethods("*")
                .maxAge(3600);
    }
}
